<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 400px;
            height: 50px;
            background-color: skyblue;
            text-align: center;
            line-height: 50px;
            margin: 100px auto;
        }

        input {
            height: 20px;
            outline: none;
            border: none;
        }
    </style>
</head>

<body>
    <div>
        <input type="password" id="pwd">
        <button>点击显示密码</button>
        <script>
            var pwd = document.getElementById('pwd');
            var btn = document.querySelector('button');
            var flag = 0;
            btn.onclick = function() {
                if(flag == 0) {
                    btn.innerHTML = '再点击隐藏密码';
                    pwd.type = 'text';
                    flag = 1;
                } else {
                    btn.innerHTML = '点击显示密码';
                    pwd.type = 'password';
                    flag = 0;
                }
            }
        </script>

    </div>
</body>

</html>